import { fromJS } from 'immutable';
import * as constants from './constants';

// current: 分页当前页码
// isLoading: pagination
// appUserData: 用户数据
// dialogVisible: 对话框是否显示 boolean
// dialogData: 动态
// searchId: 搜索框搜索用户编号
// searchUsername: 搜索框搜索用户名
const defaultState = fromJS({
  current: 1,
  isLoading: false,
  appUserData: [],
  dialogVisible: false,
  dialogData: [],
  searchId: '',
  searchFormValue: {
    id: '',
  }
});

export default (state = defaultState, action) => {
  switch(action.type) {
    case constants.GET_APPUSERDATA:
      return state.set("appUserData", fromJS(action.appUserData));
    case constants.OPEN_DIALOG:
      return state.merge({
        dialogVisible: true,
        dialogData: fromJS(action.dialogData)
      });
    case constants.CLOSE_DIALOG:
      return state.set("dialogVisible", false);
    case constants.SEARCHFORM_CHANGE:
      // return state.set("searchFormValue", action.searchFormValue);
      return state.merge({
        searchId: action.searchId
      });
    default:
      return state;
  }
}